/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import model.entities.Room;
import model.entities.RoomStatus;
import model.entities.RoomType;

/**
 *
 * @author Hieu.Nguyen
 */
public class RoomStatusDAO {
    private static RoomStatusDAO roomStatusDAO;

    public static RoomStatusDAO getInstance() {
        if (roomStatusDAO == null) {
            roomStatusDAO = new RoomStatusDAO();
        }
        return roomStatusDAO;
    }
    
     public List<RoomStatus> getRoomStatus(boolean isActived) {
        List<RoomStatus> listRoomST = new ArrayList<RoomStatus>();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblRoomStatus";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                RoomStatus r = new RoomStatus();
                r.setRoomStatusID(rs.getInt("RoomStatusID"));
                r.setRoomStatusName(rs.getString("RoomStatusName"));
                r.setRoomStatusDesc(rs.getBoolean("RoomStatusDesc"));
                listRoomST.add(r);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listRoomST;
    }
    public RoomStatus getRoomStatusByID(int roomStatusID, boolean desc) {

        RoomStatus rt = new RoomStatus();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblRoomStatus where RoomStatusID = ? and RoomStatusDesc = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, roomStatusID);
            pstmt.setBoolean(2, desc);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                
                rt.setRoomStatusID(rs.getInt("RoomStatusID"));
                rt.setRoomStatusName(rs.getString("RoomStatusName"));
                rt.setRoomStatusDesc(rs.getBoolean("RoomStatusDesc"));
             
                
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return rt;
     }
    
    public boolean createRoomStatus(RoomStatus roomStatus) {
        boolean isCheck = false;
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "insert into tblRoomStatus values (?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
           
            pstmt.setString(1, roomStatus.getRoomStatusName());
            pstmt.setBoolean(2, roomStatus.isRoomStatusDesc());
            pstmt.executeUpdate();
            isCheck = true;
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return isCheck;
     }
}
